import * as constants from './constants';
import axios from 'axios';
import {
	fromJS
} from 'immutable';


const getSearchItemData = (data) => ({
	type: constants.CHANGE_LIST,
	data: fromJS(data),
	totalPage: Math.ceil(data.length / 10)
});

export const searchFocused = () => ({
	type: constants.SEARCH_FOCUSED
});

export const searchBlur = () => ({
	type: constants.SEARCH_BLUR
});

export const mouseEnter = () => ({
	type: constants.MOUSE_ENTER
});

export const mouseLeave = () => ({
	type: constants.MOUSE_LEAVE
});

export const changePage = (page) => ({
	type: constants.CHANGE_PAGE,
	page
});

export const getSearchItemList = () => {
	return (dispatch) => {
		axios.get('/api/SearchList.json')
			.then((res) => {
				const data = res.data;
				dispatch(getSearchItemData(data.data));
			}).catch(() => {
				console.log("error");
			});
	}
};